package com.qxbb.report.controller;

import com.qxbb.report.bo.*;
import com.qxbb.report.service.ChainSalesOrderService;
import com.qxbb.report.service.ChainStoreService;
import com.qxbb.report.service.ChainUserInforService;
import com.qxbb.report.utils.StringUtils;
import com.qxbb.report.utils.http.HttpResult;
import com.qxbb.report.vo.ChainSalesOrderVO;
import com.qxbb.report.vo.HeadQuartersOrdersVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;



/**
 * @version 1.0
 * @author: pebble
 * @data 2023/9/29 15:29
 */
@RestController
@RequestMapping("chain")
@CrossOrigin
public class ChainController {

    Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private ChainUserInforService chainUserInforService;

    @Autowired
    private ChainStoreService chainStoreService;

    @Autowired
    private ChainSalesOrderService chainSalesOrderService;

    /**
     * 根据店铺id获取店铺名称
     * @param storeId
     * @return
     */
    @GetMapping("/getChainName/{storeId}")
    public HttpResult selectChainName(@PathVariable("storeId")Integer storeId){
        logger.info(this.getClass() + ".selectChainName 根据店铺id获取店铺名称:{}", storeId);
        return HttpResult.ok(chainStoreService.selectChainName(storeId));
    }

    /**
     * 连锁店普通员工 -- >连锁店销售报表
     * @return
     */
    @PostMapping("/orderSaler")
    public HttpResult selectChainSalesOrder(@RequestBody ChainOrderSalerBO chainOrderSalerBO){
        logger.info(this.getClass() + ".selectChainSalesOrder 进入连锁店销售报表:{}", chainOrderSalerBO);
        ChainSalesOrderVO chainSalesOrderVO =  chainSalesOrderService.selectChainSaleOrder(chainOrderSalerBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该时间段没有销售报表记录！");
    }

    /**
     * 连锁店普通员工 -- >连锁店月销售报表
     * @return
     */
    @PostMapping("/orderSaler/week")
    public HttpResult selectChainOrderWeek(@RequestBody ChainOrderWeekBO chainOrderWeekBO) throws ParseException {
        logger.info(this.getClass() + ".selectChainOrderWeek 连锁店月销售报表:{}", chainOrderWeekBO);
        return HttpResult.ok(chainSalesOrderService.selectChainOrderWeek(chainOrderWeekBO));
    }

    /**
     *  查询当月日历
     * @return
     */
    @PostMapping("/month")
    public HttpResult selectMonth(@RequestBody ChainOrderWeekBO chainOrderWeekBO) throws ParseException {
        logger.info(this.getClass() + ".selectMonth 连锁店月销售报表:{}", chainOrderWeekBO);
        return HttpResult.ok(chainSalesOrderService.selectMonth(chainOrderWeekBO));
    }


    /**
     * 管理员总督 -- > 所有连锁店销售详情
     * @return
     */
    @PostMapping("/headQuartersOrders")
    public HttpResult selectHeadQuartersOrders(@RequestBody HeadQuartersSalersBO headQuartersSalersBO){
        logger.info(this.getClass() + ".selectHeadQuartersOrders 管理员总督 -- > 所有连锁店销售详情:{}", headQuartersSalersBO);
        List<HeadQuartersOrdersVO> ordersVOS =  chainSalesOrderService.selectHeadQuartersOrder(headQuartersSalersBO);
        if (!ordersVOS.isEmpty()){
            return HttpResult.ok(ordersVOS);
        }
        return HttpResult.ok("该时间段没有销售报表记录！");
    }


    /**
     * 连锁店经营者-->所有店铺销售报表
     * @return
     */
    @PostMapping("/operatorAll")
    public HttpResult selectOperatorAll(@RequestBody OperatorBO operatorBO){
        logger.info(this.getClass() + ".selectOperatorAll 连锁店经营者-->所有店铺销售报表:{}", operatorBO);
        List<HeadQuartersOrdersVO> ordersVOS =  chainSalesOrderService.selectOperatorAll(operatorBO);
        if (!ordersVOS.isEmpty()){
            return HttpResult.ok(ordersVOS);
        }
        return HttpResult.ok("该时间段没有销售报表记录！");
    }


    /**
     * 查询连锁店经手人
     * @return
     */
    @GetMapping("/clerk/{chainId}")
    public HttpResult selectClerk(@PathVariable("chainId")String chainId){
        logger.info(this.getClass() + ".selectClerk 查询连锁店经手人:{}", chainId);
        return HttpResult.ok(chainUserInforService.selectClerk(chainId));
    }


    /**
     * 查询所有连锁店经手人
     * @return
     */
    @GetMapping("/clerkAll")
    public HttpResult selectClerkAll(){
        logger.info(this.getClass() + ".selectClerkAll 查询所有连锁店经手人");
        return HttpResult.ok(chainUserInforService.selectClerkAll());
    }


    /**
     * 查询连锁店下拉框
     * @return
     */
    @GetMapping("/store/{userId}/{userType}")
    public HttpResult selectStore(@PathVariable("userId")Integer userId,@PathVariable("userType")Integer userType){
        logger.info(this.getClass() + ".selectStore 查询连锁店下拉框,用户id:{},用户类别:{}", userId,userType);
        return HttpResult.ok(chainStoreService.selectStoreId(userId,userType));
    }

}
